import { createRouter, createWebHashHistory } from 'vue-router';

const routes = [
  {
    path: '/car',
    component: () => import('../views/car/index')
  },
  {
    path: '/china',
    component: () => import('../views/china/index')
  },
  {
    path: '/china/2',
    component: () => import('../views/china2/index')
  },
  {
    path: '/earth',
    component: () => import('../views/earth/index')
  },
  {
    path: '/earth/2',
    component: () => import('../views/earth/index2')
  },
  {
    path: '/earth/3',
    component: () => import('../views/earth/index3')
  },
  {
    path: '/earth/4',
    component: () => import('../views/earth/index4')
  },
  {
    path: '/learn',
    component: () => import('../views/learn/index')
  },
  {
    path: '/main',
    component: () => import('../layout/menuLayout.vue'),
    children: [
      { path: '/main/list', component: () => import('../views/main/list') },
      { path: '/main/info', component: () => import('../views/main/info') },
      { path: '/main/echarts', component: () => import('../views/echarts') }
    ]
  },
  {
    path: '/main',
    component: () => import('../layout/menuLayout.vue'),
    children: [
      {
        path: '/main/home',
        component: () => import('../views/home')
      },
      {
        path: '/main/virtual/scroll/table',
        component: () => import('../views/virtualScroll/list')
      },
      {
        path: '/main/virtual/scroll/card',
        component: () => import('../views/virtualScroll')
      },
      {
        path: '/main/form',
        component: () => import('../views/form/index.vue')
      },
      {
        path: '/main/jsx/table',
        component: () => import('../views/jsxTable/index.vue')
      },
      {
        path: '/main/jsx/table2',
        component: () => import('../views/jsxTable/index2.vue')
      }
    ]
  },
  {
    path: '/design/form',
    component: () => import('../views/formDesign/index.vue')
  }
];

const router = createRouter({
  history: createWebHashHistory(),
  routes
});

router.beforeEach((to, from, next) => {
  if (to.query.token) {
    next(to.path);
    return;
  }
  // console.log(to.path, to.query);
  next();
});
export default router;
